/*----------------------------------------------------------------------------
 * snspost
 * ---------------------------------------------------------------------------
 * Date      : 2011-08-22
 * Author    : Testking
 * ---------------------------------------------------------------------------
 * USAGE
 * ---------------------------------------------------------------------------
 *
 * ---------------------------------------------------------------------------
 * EXAMPLE
 * ---------------------------------------------------------------------------
 *
 *----------------------------------------------------------------------------
 */
(function($){
	$.fn.snspost = function(opts) {
		var loc = '';
		opts = $.extend({}, {type:'twitter', event:'click', content:'', url:'', summary:'', writer:''}, opts);
		opts.content = encodeURIComponent(opts.content);
    opts.url = encodeURIComponent(opts.url);
		switch(opts.type) {
			case 'me2day' :
				loc = 'http://me2day.net/posts/new?new_post[body]='+opts.content + ' ' + opts.url;
				if (opts.tag) loc += '&new_post[tags]='+encodeURIComponent(opts.tag);
				break;
			case 'facebook' :
				loc = 'http://www.facebook.com/share.php?t='+opts.content+'&u='+opts.url;
				break;
			case 'yozm' :
				loc = 'http://yozm.daum.net/api/popup/prePost?sourceid=54&link=' + opts.url + '&prefix=' + opts.content + '&parameter=' + opts.content;
				break;
			case 'clog' :
				loc = 'http://csp.cyworld.com/bi/bi_recommend_pop.php?url=' + opts.url + '&title_nobase64=' + opts.content + '&summary_nobase64=' + encodeURIComponent(opts.summary) + '&writer=' + encodeURIComponent(opts.writer);
				break;
			case 'delicious' :
				loc = 'http://www.delicious.com/save?v=5&noui&jump=close&url='+ opts.url +'&title='+opts.content;
				break;
			case 'twitter' :
			default:
				loc = 'http://twitter.com/home?status='+opts.content + ' ' + opts.url;
				break;
		}
		this.bind(opts.event, function(){
			window.open(loc);
			return false;
		});
	};
	$.snspost = function(selectors, action) {
		$.each(selectors, function(key,val) {
			$(val).snspost( $.extend({}, action, {type:key}) );
		});
	};
})(jQuery);